import Home from "@/views/Home";
// 数据查询
import DataQuery from "@/views/DataQuery";
// 节点导引
import NodeGuidance from "@/views/NodeGuidance";
// 监控与统计
import Monitoring from "@/views/Monitoring";
// 新闻资讯
import News from "@/views/News";
import NewsDesc from "@/views/News/NewsDesc";
// 新闻配置
import NewsConfig from "@/views/NewsConfig";
import AddNew from "@/views/NewsConfig/AddNew";
import NewsUpdate from "@/views/NewsConfig/NewsUpdate";
import NewsPreview from "@/views/NewsConfig/NewsPreview";

// 登录
import Login from "@/views/Login";
import UserInfo from "@/views/UserInfo";

// 不存在路径
import NotFound from "@/views/NotFound";

// Navigate重定向组件
import { Navigate, Outlet } from "react-router-dom";

// 定义PrivateRoute组件，用于包裹需要权限验证的路由
const PrivateRoute = () => {
  const auth = localStorage.getItem("lanmei_token"); // 获取用户认证状态
  return auth ? <Outlet /> : <Navigate to="/login" replace />;
};

const routes = [
  {
    path: "/",
    element: <Navigate to="/dataQuery" />,
  },
  {
    path: "/",
    element: <Home />,
    children: [
      {
        path: "dataQuery",
        element: <DataQuery />,
      },
      {
        path: "nodeGuidance",
        element: <NodeGuidance />,
      },
      {
        path: "monitor",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <Monitoring />,
          },
        ],
      },
      {
        path: "news",
        element: <News />,
      },
      {
        path: "news/:id",
        element: <NewsDesc />,
      },
      {
        path: "newsConfig",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <NewsConfig />,
          },
        ],
      },
      {
        path: "newsConfig/addNew",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <AddNew />,
          },
        ],
      },
      {
        path: "newsConfig/newsUpdate/:id",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <NewsUpdate />,
          },
        ],
      },
      {
        path: "newsConfig/newsPreview/:id",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <NewsPreview />,
          },
        ],
      },
      {
        path: "userInfo",
        element: <PrivateRoute />, // 使用PrivateRoute包裹需要权限验证的monitor页面
        children: [
          {
            path: "",
            element: <UserInfo />,
          },
        ],
      },
    ],
  },
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "*",
    element: <NotFound />,
  },
];
export default routes;
